import { reqGetSearchInfo } from '@/api'
//search小仓库
const state = {
    searchList: {}
}
const mutations = {
    GETSEARCHLIST(state, searchList) {
        // 保存到组件的state(仓库)
        state.searchList = searchList;
    }
}
const actions = {
    // 获取search模块数据
    async getSearchList({ commit }, params = {}) {
        // params形参:当派发action时候,第二个参数传过来的
        let result = await reqGetSearchInfo(params);
        // console.log(result);

        //如果成功接收到服务器返回的数据,就commit,给mutations保存到组件的state
        if (result.code == 200) {
            commit("GETSEARCHLIST", result.data);
        }
    }
}

//getters多用于简化仓库中的数据
const getters = {
    //简化仓库中的goodsList数据,方便存储
    // getters里函数的参数为： 当前仓库的state
    goodsList(state) {
        return state.searchList.goodsList;
    },

    //简化仓库里的trademarkList和attrsList数据
    trademarkList(state) {
        return state.searchList.trademarkList;
    },
    attrsList(state) {
        return state.searchList.attrsList;
    }
}

export default {
    state,
    mutations,
    actions,
    getters
}

//dispatch 第二个参数传来的value